define(function(require){
    $(function(){
    	
    	/*----------------------------------------- 媒体资源 -----------------------------------------*/
    	
    	/* 日期选择 */
    	$('[name=reservation]').daterangepicker({
    		format:'YYYY-MM-DD'
    	}, function(start, end, label) {
    		console.log(start.toISOString(), end.toISOString(), label);
    	});
    	
    	/* 搜索 */
    	$('.searchbox-btn').click(function(){
    		var txt = $('.searchbox-ipt').val();
    		if(semi.utils.isEmpty(txt))return;
    		totalData = [
    		             {ad:'P17', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    		             {ad:'P18', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    		             {ad:'P19', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    		             {ad:'P20', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    		             ];
    		grid.send();
    		return;
    		$ajax.ajax({
    			url: 'xxx.html',//TODO
    			data: {
    				text:txt
    			},
    			success:function(data){
    				totalData = [
    				             {ad:'P17', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    				             {ad:'P18', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    				             {ad:'P19', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    				             {ad:'P20', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
    				             ];
    				grid.send();
    			}
    		});
    	});
    	
    	var pageTemplate =
            '<div class="gridTotal">共<b>{totalCount}</b>个广告活动</div>' +
            '<input type="button" value="首页" class="page-bt first-page" title="首页">' +
            '<input type="button" value="上一页" class="page-bt pre-page" title="上一页">' +
            '第{pageNo}页' +
            '<input type="button" value="下一页" class="page-bt next-page" title="下一页">' +
            '<input type="button" value="末页" class="page-bt last-page" title="末页">' +
            '共{totalPage}页&nbsp;&nbsp;跳转至' +
            '<input type="text" size="4" maxlength="5" class="some-page"/>' +
            '每页<select class="page-size"><option value="10">10</option><option value="20">20</option></select>条记录';
    	
    	/*----------------- 流量采购&管理者 --------------------------*/
         var bodyTemplate =
             '<tr>'
         	 + '<td class="txtc">{position_name}</td>'
         	 + '<td class="txtc">{position_size}</td>'
         	 + '<td class="txtc">{media_name}</td>'
         	 + '<td class="txtc">{media_attrs}</td>'
             + '<td class="txtc">{circle}</td>'
             + '<td class="txtc">{bid_type}</td>'
             + '<td class="txtc">{bid_price}</td>'
             + '<td class="txtc">{pv}</td>'
             + '<td class="txtc">{click}</td>'
             + '<td class="txtc">{shared}</td>'
             + '<td class="txtc">{floor}</td>'
             + '<td class="txtc"><a class="ibtn showPos" href="javascript:;">查看报表</a></td>'
             + '</tr>';
        
        var totalData = [
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'},
			{position_name:'首页顶通', position_size:'900x80', media_name:'迅雷', media_attrs:'视频网站', circle:'4.1-4.30', bid_type:'CPD', bid_price:'1000元/天', pv:'450', click:'500', shared:'平台', floor:'1元'}
        ];
       
        var grid = Grid.init({
            holder:'mediaResources',
            bodyTemplate:bodyTemplate,
            dataSource:{
              	 bodyData: totalData,
               	 pageNo: 1,
               	 pageSize: 10,
               	 totalCount: 10,
               	 totalPage:  1
            },
            pageSize:10,
            pageTemplate:pageTemplate
        });
        grid.send();
        
        $('.showPos').on('click', function(){
        	$dialog({
                title: false,
                width: 500,
                content: $('.pop-position').clone().show()[0],
                button: [
                     {
                         value: '修改',
                         callback: function () {
                         },
                         autofocus: true
                     },
                     {
                         value: '取消'
                     }
                 ]
            }).showModal();
        });
        
        
        
        /*----------------- 平台流量使用者 --------------------------*/
        var bodyTemplate2 =
            '<tr>'
            + '<td class="txtc">{ad}</td>'
            + '<td class="txtc">{adAttr}</td>'
            + '<td class="txtc">{media}</td>'
            + '<td class="txtc">{mediaAttr}</td>'
            + '<td class="txtc">{date}</td>'
            + '<td class="txtc">{cpm}</td>'
            + '<td class="txtc">{cpc}</td>'
            + '<td class="txtc">{price}</td>'
            + '<td class="txtc"><a class="ibtn" href="javascript:;">设置策略</a><a class="ibtn" href="javascript:;">查看报表</a></td>'
            + '</tr>';
        
        var totalData2 = [
            {ad:'P1', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P2', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P3', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P4', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P5', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P6', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P7', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P8', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P9', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P10', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P11', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P12', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P13', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P14', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P15', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P16', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P17', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P18', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P19', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'},
            {ad:'P20', adAttr:'新闻', media:'迅雷', mediaAttr:'视频', date:'2014-05-01', cpm:'100', cpc:'100', price:'2元/CPM'}
        ];
        
        var grid2 = Grid.init({
            holder:'mediaResources2',
            bodyTemplate:bodyTemplate2,
            dataSource:{
              	 bodyData: totalData2,
               	 pageNo: 1,
               	 pageSize: 10,
               	 totalCount: 20,
               	 totalPage:  2
            },
            pageSize:10,
            pageTemplate:pageTemplate
        });
        grid2.send();
    });
});